package com.yjlove.myplay.mvptest.biz;

import com.yjlove.myplay.mvptest.bean.User;
import com.yjlove.myplay.utils.SP;
import com.yjlove.myplay.common.StringSpKey;

/**
 * 作者 YJlvoe
 * 创建时间 2017/1/18.
 */
public class UserBiz implements IUserBiz {
    @Override
    public void login(final String username, final String password, final OnLoginListener loginListener) {
        //模拟子线程耗时操作
        new Thread() {
            @Override
            public void run() {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //模拟登录成功
                if ("yj".equals(username) && "123".equals(password)) {
                    User user = new User();
                    user.setUsername(username);
                    user.setPassword(password);
                    SP.save(StringSpKey.USER_NAME, username);
                    SP.save(StringSpKey.PASS_WORD, password);
                    loginListener.loginSuccess(user);
                } else {
                    loginListener.loginFailed();
                }
            }
        }.start();
    }
}
